package com.fanxuankai.boot.canal.listener;

import com.alibaba.fastjson.JSON;
import com.fanxuankai.boot.canal.domain.User;
import com.fanxuankai.boot.canal.listener.annotation.CanalListener;
import com.fanxuankai.boot.canal.listener.annotation.Delete;
import com.fanxuankai.boot.canal.listener.annotation.Insert;
import com.fanxuankai.boot.canal.listener.annotation.Update;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author fanxuankai
 */
@Slf4j
@Service
@CanalListener(entityClass = User.class)
public class UserCanalListener {
    @Insert
    public void insert(User insert) {
        log.info(JSON.toJSONString(insert));
    }

    @Update
    public void update(User before, User after) {
        log.info(JSON.toJSONString(before));
        log.info(JSON.toJSONString(after));
    }

    @Delete
    public void delete(User delete) {
        log.info(JSON.toJSONString(delete));
    }
}
